package Eyjafjalla.patch;

import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.character.Eyjafjalla;
import Eyjafjalla.effect.CampfireMarkEffect;
import Eyjafjalla.helper.EyjafjallaHelper;
import Eyjafjalla.helper.FireMarkOption;
import Eyjafjalla.helper.ImageHelper;
import Eyjafjalla.helper.StringHelper;
import Eyjafjalla.modcore.ClassEnum;
import basemod.ReflectionHacks;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePostfixPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePrefixPatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DescriptionLine;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.localization.LocalizedStrings;
import com.megacrit.cardcrawl.localization.UIStrings;
import com.megacrit.cardcrawl.rooms.CampfireUI;
import com.megacrit.cardcrawl.screens.select.GridCardSelectScreen;
import com.megacrit.cardcrawl.ui.campfire.AbstractCampfireOption;
import com.megacrit.cardcrawl.vfx.cardManip.CardGlowBorder;
import org.omg.CORBA.PRIVATE_MEMBER;

import java.sql.Ref;
import java.util.ArrayList;

public class FirePatch {

    private static final UIStrings uiStrings;
    private static final GlyphLayout gl;
    private static final StringBuilder sbuilder;
    private static final float CARD_ENERGY_IMG_WIDTH;
    private static final float DESC_BOX_WIDTH = Settings.BIG_TEXT_MODE ? AbstractCard.IMG_WIDTH * 0.95F : AbstractCard.IMG_WIDTH * 0.79F;
    private static final float DESC_OFFSET_Y = -(Settings.BIG_TEXT_MODE ? AbstractCard.IMG_HEIGHT * 0.24F : AbstractCard.IMG_HEIGHT * 0.255F) - 114F*Settings.scale;

    public static boolean unChinese = false;
    public static boolean hasFireMark = false;
    public static int fireMarkAmount = 0;

    //根据计数器设置
    @SpirePatch(clz = AbstractCard.class,method = "updateGlow")
    public static class UpdateGlowPatch{
        @SpirePostfixPatch
        public static void Postfix(AbstractCard _inst){
            if(CloudPatch.CloudField.showFire.get(_inst)){
                float timer = CloudPatch.CloudField.fireTimer.get(_inst);
                timer += Gdx.graphics.getDeltaTime() * 0.8F;
                //0.5 - 0.9 - 0.5
                if(timer > 0.8F)
                    timer = 0F;
                CloudPatch.CloudField.fireTimer.set(_inst,timer);
            }
        }
    }

    //特殊图标渲染
    @SpirePatch(clz = AbstractCard.class,method = "renderEnergy",paramtypez = {SpriteBatch.class})
    public static class RenderCardPatch{
        @SpireInsertPatch(rloc = 0,localvars = {"renderColor"})
        public static void Insert(AbstractCard _inst, SpriteBatch sb, Color renderColor){
            //云层
//            if(CloudPatch.CloudField.inCloud.get(_inst)){
//                ImageHelper.drawSpecialImgOnCard(_inst,3,sb,renderColor);
//            }
            //炎息
            if(CloudPatch.CloudField.isFire.get(_inst)){
                ImageHelper.drawSpecialImgOnCard(_inst,0,sb,renderColor);
            }
            //todo
            renderFire(_inst,sb);
        }
    }

    //特殊keyword渲染，其中还包含绑定（即炎息标记一定会展示炎息keyword）
    @SpirePatch(clz = AbstractCard.class,method = "initializeDescription")
    public static class RenderCardTipPatch{
        @SpirePostfixPatch
        public static void Postfix(AbstractCard _inst){
            if(CloudPatch.CloudField.showFire.get(_inst)){
                if(!_inst.keywords.contains(uiStrings.TEXT[0]))
                    _inst.keywords.add(uiStrings.TEXT[0]);
            }
        }
    }

    //整体渲染（预计位置在卡图处）
    public static void renderFire(AbstractCard c,SpriteBatch sb) {
        if (!CloudPatch.CloudField.showFire.get(c))
            return;
        boolean full = false;
        if(AbstractDungeon.player!=null&&AbstractDungeon.isPlayerInDungeon()&&!AbstractDungeon.isScreenUp){
            full = AbstractDungeon.player.hoveredCard==c || (CloudPatch.CloudField.isFire.get(c) || hasFireMark);
        }
        else {
            full=c.hb.hovered || (c.isGlowing && (CloudPatch.CloudField.isFire.get(c) || hasFireMark));
        }
        renderFireImage(c, full, sb);

        if (full) {
            if (Settings.lineBreakViaCharacter) {
                renderDescriptionCN(c, c.current_x, c.current_y + DESC_OFFSET_Y * c.drawScale, sb);
            } else {
                renderExtraDescription(c, c.current_x, c.current_y + DESC_OFFSET_Y * c.drawScale, sb);
            }
        }
    }

    //得到描述
    public static void initializeFireDescription(AbstractCard c){
        ArrayList<String> foreKeywords = new ArrayList<>(c.keywords);
        ArrayList<DescriptionLine> foreLines = new ArrayList<>(c.description);
        String foreRaw = c.rawDescription;
        c.rawDescription = CloudPatch.CloudField.fireDescription.get(c);
        c.initializeDescription();
        CloudPatch.CloudField.fireLines.set(c,c.description);
        for(int i =0;i<foreKeywords.size();i++){
            if(!c.keywords.contains(foreKeywords.get(i))){
                c.keywords.add(foreKeywords.get(i));
            }
        }
        c.rawDescription = foreRaw;
        c.description = foreLines;
    }

    //炎息效果的渲染：图片
    private static void renderFireImage(AbstractCard c,boolean fullPreview,SpriteBatch sb){
        if(fullPreview){
            Color color = Color.WHITE.cpy();
            color.a = 0.9F;
            color.a *= c.transparency;
            ImageHelper.drawSpecialImgOnCard(c,1,sb,color);
        }

        if(c.isGlowing&&(CloudPatch.CloudField.isFire.get(c)||hasFireMark)){
            Color border = Color.GOLD.cpy();
            border.a = 0.9F - Math.abs(CloudPatch.CloudField.fireTimer.get(c)-0.4F);
            border.a *= c.transparency;
            ImageHelper.drawSpecialImgOnCard(c,2,sb,border);
        }
    }

    //炎息效果的渲染：描述
    private static void renderExtraDescription(AbstractCard c,float draw_x,float draw_y,SpriteBatch sb){
        //float draw_y = c.current_y - AbstractCard.IMG_HEIGHT * c.drawScale / 2.0F + AbstractCard.DESC_OFFSET_Y * c.drawScale;
        ArrayList<DescriptionLine> description = CloudPatch.CloudField.fireLines.get(c);
        BitmapFont font = getDescFont(c,description.size());
        draw_y += (float)description.size() * font.getCapHeight() * 0.775F - font.getCapHeight() * 0.375F;
        Color textColor = ((Color) ReflectionHacks.getPrivate(c,AbstractCard.class,"textColor")).cpy();
        Color goldColor = ((Color) ReflectionHacks.getPrivate(c,AbstractCard.class,"goldColor")).cpy();

        float spacing = 1.45F * -font.getCapHeight() / Settings.scale / c.drawScale;

        for(int i = 0; i < description.size(); ++i) {
            float start_x = draw_x - ((DescriptionLine)description.get(i)).width * c.drawScale / 2.0F;
            String[] var7 = ((DescriptionLine)description.get(i)).getCachedTokenizedText();
            int var8 = var7.length;

            for(int var9 = 0; var9 < var8; ++var9) {
                String tmp = var7[var9];
                if (tmp.length() > 0 && tmp.charAt(0) == '*') {
                    tmp = tmp.substring(1);
                    String punctuation = "";
                    if (tmp.length() > 1 && tmp.charAt(tmp.length() - 2) != '+' && !Character.isLetter(tmp.charAt(tmp.length() - 2))) {
                        punctuation = punctuation + tmp.charAt(tmp.length() - 2);
                        tmp = tmp.substring(0, tmp.length() - 2);
                        punctuation = punctuation + ' ';
                    }

                    gl.setText(font, tmp);
                    FontHelper.renderRotatedText(sb, font, tmp, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, goldColor);
                    start_x = (float)Math.round(start_x + gl.width);
                    gl.setText(font, punctuation);
                    FontHelper.renderRotatedText(sb, font, punctuation, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    gl.setText(font, punctuation);
                    start_x += gl.width;
                } else if (tmp.length() > 0 && tmp.charAt(0) == '!') {
                    if (tmp.length() == 4) {
                        start_x += renderDynamicVariable(c,tmp.charAt(1), start_x, draw_y, i, font, sb, (Character)null);
                    } else if (tmp.length() == 5) {
                        start_x += renderDynamicVariable(c,tmp.charAt(1), start_x, draw_y, i, font, sb, tmp.charAt(3));
                    }
                } else if (tmp.equals("[R] ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_red, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[R]. ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale / Settings.scale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_red, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    FontHelper.renderRotatedText(sb, font, LocalizedStrings.PERIOD, c.current_x, c.current_y, start_x - c.current_x + CARD_ENERGY_IMG_WIDTH * c.drawScale, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                    gl.setText(font, LocalizedStrings.PERIOD);
                    start_x += gl.width;
                } else if (tmp.equals("[G] ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_green, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[G]. ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_green, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    FontHelper.renderRotatedText(sb, font, LocalizedStrings.PERIOD, c.current_x, c.current_y, start_x - c.current_x + CARD_ENERGY_IMG_WIDTH * c.drawScale, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                } else if (tmp.equals("[B] ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_blue, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[B]. ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_blue, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    FontHelper.renderRotatedText(sb, font, LocalizedStrings.PERIOD, c.current_x, c.current_y, start_x - c.current_x + CARD_ENERGY_IMG_WIDTH * c.drawScale, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                } else if (tmp.equals("[W] ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_purple, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[W]. ")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_purple, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    FontHelper.renderRotatedText(sb, font, LocalizedStrings.PERIOD, c.current_x, c.current_y, start_x - c.current_x + CARD_ENERGY_IMG_WIDTH * c.drawScale, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                } else {
                    gl.setText(font, tmp);
                    FontHelper.renderRotatedText(sb, font, tmp, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                }
            }
        }

        font.getData().setScale(1.0F);
    }

    private static void renderDescriptionCN(AbstractCard c,float draw_x,float draw_y,SpriteBatch sb){
        //float draw_y = this.current_y - IMG_HEIGHT * this.drawScale / 2.0F + DESC_OFFSET_Y * this.drawScale;
        ArrayList<DescriptionLine> description = CloudPatch.CloudField.fireLines.get(c);
        BitmapFont font = getDescFont(c,description.size());
        draw_y += (float)description.size() * font.getCapHeight() * 0.775F - font.getCapHeight() * 0.375F;

        float spacing = 1.45F * -font.getCapHeight() / Settings.scale / c.drawScale;

        Color textColor = ((Color) ReflectionHacks.getPrivate(c,AbstractCard.class,"textColor")).cpy();
        Color goldColor = ((Color) ReflectionHacks.getPrivate(c,AbstractCard.class,"goldColor")).cpy();

        for(int i = 0; i < description.size(); ++i) {
            float start_x = 0.0F;
            if (Settings.leftAlignCards) {
                start_x = draw_x - DESC_BOX_WIDTH * c.drawScale / 2.0F + 2.0F * Settings.scale;
            } else {
                start_x = draw_x - ((DescriptionLine)description.get(i)).width * c.drawScale / 2.0F - 14.0F * Settings.scale;
            }

            String[] var7 = ((DescriptionLine)description.get(i)).getCachedTokenizedTextCN();
            int var8 = var7.length;

            for(int var9 = 0; var9 < var8; ++var9) {
                String tmp = var7[var9];
                String updateTmp = null;

                int j;
                for(j = 0; j < tmp.length(); ++j) {
                    if (tmp.charAt(j) == 'D' || tmp.charAt(j) == 'B' && !tmp.contains("[B]") || tmp.charAt(j) == 'M') {
                        updateTmp = tmp.substring(0, j);
                        updateTmp = updateTmp + getDynamicValue(c,tmp.charAt(j));
                        updateTmp = updateTmp + tmp.substring(j + 1);
                        break;
                    }
                }

                if (updateTmp != null) {
                    tmp = updateTmp;
                }

                for(j = 0; j < tmp.length(); ++j) {
                    if (tmp.charAt(j) == 'D' || tmp.charAt(j) == 'B' && !tmp.contains("[B]") || tmp.charAt(j) == 'M') {
                        updateTmp = tmp.substring(0, j);
                        updateTmp = updateTmp + getDynamicValue(c,tmp.charAt(j));
                        updateTmp = updateTmp + tmp.substring(j + 1);
                        break;
                    }
                }

                if (updateTmp != null) {
                    tmp = updateTmp;
                }

                if (tmp.length() > 0 && tmp.charAt(0) == '*') {
                    tmp = tmp.substring(1);
                    String punctuation = "";
                    if (tmp.length() > 1 && tmp.charAt(tmp.length() - 2) != '+' && !Character.isLetter(tmp.charAt(tmp.length() - 2))) {
                        punctuation = punctuation + tmp.charAt(tmp.length() - 2);
                        tmp = tmp.substring(0, tmp.length() - 2);
                        punctuation = punctuation + ' ';
                    }

                    gl.setText(font, tmp);
                    FontHelper.renderRotatedText(sb, font, tmp, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, goldColor);
                    start_x = (float)Math.round(start_x + gl.width);
                    gl.setText(font, punctuation);
                    FontHelper.renderRotatedText(sb, font, punctuation, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    gl.setText(font, punctuation);
                    start_x += gl.width;
                } else if (tmp.equals("[R]")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_red, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[G]")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_green, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[B]")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_blue, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else if (tmp.equals("[W]")) {
                    gl.width = CARD_ENERGY_IMG_WIDTH * c.drawScale;
                    c.renderSmallEnergy(sb, AbstractCard.orb_purple, (start_x - c.current_x) / Settings.scale / c.drawScale, -100.0F - (((float)description.size() - 4.0F) / 2.0F - (float)i + 1.0F) * spacing);
                    start_x += gl.width;
                } else {
                    gl.setText(font, tmp);
                    FontHelper.renderRotatedText(sb, font, tmp, c.current_x, c.current_y, start_x - c.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - c.current_y + -6.0F, c.angle, true, textColor);
                    start_x += gl.width;
                }
            }
        }

        font.getData().setScale(1.0F);
    }

    private static BitmapFont getDescFont(AbstractCard c,int lines){
        BitmapFont font = null;
        if(c.angle==0F&&c.drawScale==1F){
            font = FontHelper.cardDescFont_N;
        }
        else {
            font = FontHelper.cardDescFont_L;
        }
        if(unChinese && lines>2){
            font.getData().setScale(c.drawScale*0.85f);
        }
        else {
            font.getData().setScale(c.drawScale);
        }
        return font;
    }

    private static String getDynamicValue(AbstractCard c,char key) {
        switch(key) {
            case 'B':
                if (c.isBlockModified) {
                    if (c.block >= c.baseBlock) {
                        return "[#7fff00]" + c.block + "[]";
                    }

                    return "[#ff6563]" + c.block + "[]";
                }

                return String.valueOf(c.baseBlock);
            case 'D':
                if (c.isDamageModified) {
                    if (c.damage >= c.baseDamage) {
                        return "[#7fff00]" + c.damage + "[]";
                    }

                    return "[#ff6563]" + c.damage + "[]";
                }

                return String.valueOf(c.baseDamage);
            case 'M':
                if (c.isMagicNumberModified) {
                    if (c.magicNumber >= c.baseMagicNumber) {
                        return "[#7fff00]" + c.magicNumber + "[]";
                    }

                    return "[#ff6563]" + c.magicNumber + "[]";
                }

                return String.valueOf(c.baseMagicNumber);
            default:
                return Integer.toString(-99);
        }
    }

    private static float renderDynamicVariable(AbstractCard card,char key, float start_x, float draw_y, int i, BitmapFont font, SpriteBatch sb, Character end){
        sbuilder.setLength(0);
        Color c = null;
        int num = 0;
        switch(key) {
            case 'B':
                if (card.isBlockModified) {
                    num = card.block;
                    if (card.block >= card.baseBlock) {
                        c = Settings.GREEN_TEXT_COLOR;
                    } else {
                        c = Settings.RED_TEXT_COLOR;
                    }
                } else {
                    c = ReflectionHacks.getPrivate(card,AbstractCard.class,"textColor");
                    num = card.baseBlock;
                }
                break;
            case 'D':
                if (card.isDamageModified) {
                    num = card.damage;
                    if (card.damage >= card.baseDamage) {
                        c = Settings.GREEN_TEXT_COLOR;
                    } else {
                        c = Settings.RED_TEXT_COLOR;
                    }
                } else {
                    c = ReflectionHacks.getPrivate(card,AbstractCard.class,"textColor");
                    num = card.baseDamage;
                }
                break;
            case 'M':
                if (card.isMagicNumberModified) {
                    num = card.magicNumber;
                    if (card.magicNumber >= card.baseMagicNumber) {
                        c = Settings.GREEN_TEXT_COLOR;
                    } else {
                        c = Settings.RED_TEXT_COLOR;
                    }
                } else {
                    c = ReflectionHacks.getPrivate(card,AbstractCard.class,"textColor");
                    num = card.baseMagicNumber;
                }
        }

        sbuilder.append(Integer.toString(num));
        gl.setText(font, sbuilder);
        FontHelper.renderRotatedText(sb, font, sbuilder.toString(), card.current_x, card.current_y, start_x - card.current_x + gl.width / 2.0F, (float)i * 1.45F * -font.getCapHeight() + draw_y - card.current_y + -6.0F, card.angle, true, c);
        if (end != null) {
            FontHelper.renderRotatedText(sb, font, Character.toString(end), card.current_x, card.current_y, start_x - card.current_x + gl.width + 4.0F * Settings.scale, (float)i * 1.45F * -font.getCapHeight() + draw_y - card.current_y + -6.0F, 0.0F, true, Settings.CREAM_COLOR);
            sbuilder.append(end);
        }

        sbuilder.append(' ');
        gl.setText(font, sbuilder);
        return gl.width;
    }

    //篝火
    @SpirePatch(clz = CampfireUI.class,method = "initializeButtons")
    public static class AddFireMarkPatch{
        @SpireInsertPatch(rloc = 33,localvars = {"buttons"})
        public static void Insert(CampfireUI _inst, ArrayList<AbstractCampfireOption> buttons){
            if(AbstractDungeon.player.chosenClass != ClassEnum.Eyjafjalla_CLASS)
                return;

            boolean valid = EyjafjallaHelper.hasFireableCards();
            buttons.add(new FireMarkOption(valid));
        }
    }

    //炎息化
    @SpirePatch(clz = GridCardSelectScreen.class,method = "update")
    public static class PyroBreathPatch{
        @SpireInsertPatch(rloc = 89)
        public static void Insert(GridCardSelectScreen _inst){
            if(!(AbstractDungeon.player instanceof Eyjafjalla))
                return;
            if(!CampfireMarkEffect.isFireMarking)
                return;
            AbstractCard hovered = ReflectionHacks.getPrivate(_inst,GridCardSelectScreen.class,"hoveredCard");
            if(hovered!=null){
                _inst.upgradePreviewCard = hovered.makeStatEquivalentCopy();
                EyjafjallaHelper.markCardToFire(_inst.upgradePreviewCard,1);
                ReflectionHacks.setPrivate(_inst.upgradePreviewCard,AbstractCard.class,"isMultiDamage",false);
                _inst.upgradePreviewCard.applyPowers();
                _inst.upgradePreviewCard.displayUpgrades();
            }
        }
    }

    static {
        uiStrings = CardCrawlGame.languagePack.getUIString(StringHelper.SPECIAL_DESCRIPTION);
        gl = new GlyphLayout();
        sbuilder = new StringBuilder();
        CARD_ENERGY_IMG_WIDTH = 24.0F * Settings.scale;
    }
}
